## Figure D.1: Positive Relationship between Corporate PAC Donations and Lobbying
# Expenses, between 2008 and 2018:: --------------------------------------------

## Instructions ----------------------------------------------------------------
# Step 1: Adjust MAIN_DIR to main folder
# Step 2: Adjust DATA_DIR to where data is is located
# Step 3: Adjust FIG_DIR to where output folder is
# Step 4: Run entire script
## setup -----------------------------------------------------------------------

# clean slate
rm(list = ls())

library(tidyverse)

# set directory
MAIN_DIR <- "C:/Users/js.egb/Dropbox/campaign-lobby-paper/replication_package"

# set data folder
DATA_DIR <-  paste(MAIN_DIR, "/data/", sep = "")

# set output folder
FIG_DIR <- paste(MAIN_DIR, "/output/", sep = "")

# file to be read in
file_in1 <- paste0(DATA_DIR, "d_final_20210127.RData") # file to be input

### 3. Scatter Plot A La Ansolabehere et al 2002:
load(file_in1)

# aggregate data
ast_plot <- d_final %>% group_by(gvkey) %>%
  summarise(don_pac = sum(don_pac, na.rm = TRUE), 
            don_all = sum(don_tot, na.rm = TRUE),
            don_emp = sum(don_emp, na.rm = TRUE),
            don_ceo = sum(don_ceo, na.rm = TRUE),
            don_gov = sum(don_gov, na.rm = TRUE),
            lob = sum(lobbying_amount, na.rm = TRUE)) %>%
  filter(don_pac >= 0 & lob >= 0)

pdf(paste0(FIG_DIR, "/figure_d1.pdf"), width = 11, height = 8) # open graphics device
par(mfrow = c(1,1), mar = c(5.5,5.5,0,0), las = 1, cex.axis = 1.8, cex.lab = 2.2, cex.main = 1.8)
plot(log(ast_plot$don_pac+1), log(ast_plot$lob+1), pch = 16,col = "darkgrey", las = 0.8, font.lab = 2, axes = FALSE,
     main = "",  xlim = c(0, 18), ylim = c(0, 23),
     xlab = "", ylab = "")
grid(col = "lightgrey", lty = "solid")
points(log(ast_plot$don_pac+1), log(ast_plot$lob+1), pch = 16,col = "darkgrey", las = 0.8, font.lab = 2, 
       main = "")  
text(x = 2.75, y =  21, labels = expression(paste(beta, " = 0.88, R2 = 0.39")), cex = 1.75) # R2 = 0.195
axis(1, at = seq(0, 24, 5), labels = seq(0, 24, 5))
axis(2, at = seq(0, 25, 5), labels = seq(0, 25, 5))
clip(2,18, 0, 22)
abline(lm(log(ast_plot$lob[ast_plot$lob>0 & ast_plot$don_pac>0]) ~ log(ast_plot$don_pac[ast_plot$lob>0 & ast_plot$don_pac>0 + 1])), 
       col = "black", lwd = 4, )
title(xlab = "Log Total Donations, in US$", line = 3.5)
title(ylab = "Log Total Lobbying, in US$", line = 3.5)
dev.off() # close graphics device


